<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Caching::Actions</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Caching::Actions</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/actionpack/lib/action_controller/caching_rb.html">
                vendor/rails/actionpack/lib/action_controller/caching.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Action caching is similar to page caching by the fact that the entire
output of the response is cached, but unlike page caching, every request
still goes through the Action Pack. The key benefit of this is that filters
are run before the cache is served, which allows for authentication and
other restrictions on whether someone is allowed to see the cache. Example:
</p>
<pre>
  class ListsController &lt; ApplicationController
    before_filter :authenticate, :except =&gt; :public
    caches_page   :public
    caches_action :show, :feed
  end
</pre>
<p>
In this example, the public action doesn&#8216;t require authentication, so
it&#8216;s possible to use the faster page caching method. But both the
show and feed action are to be shielded behind the authenticate filter, so
we need to implement those as action caches.
</p>
<p>
Action caching internally uses the fragment caching and an around filter to
do the job. The fragment cache is named according to both the current host
and the path. So a page that is accessed at <a
href="http://david.somewhere.com/lists/show/1">david.somewhere.com/lists/show/1</a>
will result in a fragment named
&quot;david.somewhere.com/lists/show/1&quot;. This allows the cacher to
differentiate between &quot;david.somewhere.com/lists/&quot; and
&quot;jamis.somewhere.com/lists/&quot; &#8212; which is a helpful way of
assisting the subdomain-as-account-key pattern.
</p>
<p>
Different representations of the same resource, e.g. <tt><a
href="http://david.somewhere.com/lists">david.somewhere.com/lists</a></tt>
and <tt><a
href="http://david.somewhere.com/lists.xml">david.somewhere.com/lists.xml</a></tt>
are treated like separate requests and so are cached separately. Keep in
mind when expiring an action cache that <tt>:action =&gt;
&#8216;lists&#8216;</tt> is not the same as <tt>:action =&gt;
&#8216;list&#8217;, :format =&gt; :xml</tt>.
</p>
<p>
You can set modify the default action cache path by passing a :cache_path
option. This will be passed directly to <a
href="Actions/ActionCachePath.html#M000267">ActionCachePath.path_for</a>.
This is handy for actions with multiple possible routes that should be
cached differently. If a block is given, it is called with the current
controller instance.
</p>
<pre>
  class ListsController &lt; ApplicationController
    before_filter :authenticate, :except =&gt; :public
    caches_page   :public
    caches_action :show, :cache_path =&gt; { :project =&gt; 1 }
    caches_action :show, :cache_path =&gt; Proc.new { |controller|
      controller.params[:user_id] ?
        controller.send(:user_list_url, c.params[:user_id], c.params[:id]) :
        controller.send(:list_url, c.params[:id]) }
  end
</pre>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000265">expire_action</a>&nbsp;&nbsp;
      <a href="#M000264">protected_instance_variables_with_action_caching</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Actions/ClassMethods.html" class="link">ActionController::Caching::Actions::ClassMethods</a><br />
Class <a href="Actions/ActionCachePath.html" class="link">ActionController::Caching::Actions::ActionCachePath</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000265" class="method-detail">
        <a name="M000265"></a>

        <div class="method-heading">
          <a href="#M000265" class="method-signature">
          <span class="method-name">expire_action</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000265-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000265-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/caching.rb, line 217</span>
217:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expire_action</span>(<span class="ruby-identifier">options</span> = {})
218:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">perform_caching</span>
219:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:action</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
220:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:action</span>].<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">action</span><span class="ruby-operator">|</span>
221:             <span class="ruby-identifier">expire_fragment</span>(<span class="ruby-constant">ActionCachePath</span>.<span class="ruby-identifier">path_for</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge</span>({ <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">action</span> })))
222:           <span class="ruby-keyword kw">end</span>
223:         <span class="ruby-keyword kw">else</span>
224:           <span class="ruby-identifier">expire_fragment</span>(<span class="ruby-constant">ActionCachePath</span>.<span class="ruby-identifier">path_for</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">options</span>))
225:         <span class="ruby-keyword kw">end</span>
226:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000264" class="method-detail">
        <a name="M000264"></a>

        <div class="method-heading">
          <a href="#M000264" class="method-signature">
          <span class="method-name">protected_instance_variables_with_action_caching</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000264-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000264-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/caching.rb, line 213</span>
213:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protected_instance_variables_with_action_caching</span>
214:         <span class="ruby-identifier">protected_instance_variables_without_action_caching</span> <span class="ruby-operator">+</span> <span class="ruby-node">%w(@action_cache_path)</span>
215:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>